package cs348a.data.opt;

import java.util.List;

import cs348a.data.Site;

public abstract class AbstractPathOptimizer implements PathOptimizer{
	/**
	 * Returns the distance matrix
	 * 
	 * @param siteList
	 * @return
	 */
	public double[][] getDistances(List<Site> siteList) {
		double[][] dist = new double[siteList.size()][siteList.size()];
		
		for(int i = 0; i < siteList.size(); i++) {
			Site s = siteList.get(i);
			
			for(int j = 0; j < siteList.size(); j++) {
				if(i == j) {
					dist[i][j] = 0;
				} else {
					Site t = siteList.get(j);
					dist[i][j] = Math.sqrt( 
							(s.x-t.x)*(s.x-t.x)
							+ (s.y-t.y)*(s.y-t.y)
							+ (s.z-t.z)*(s.z-t.z));
					
					dist[j][i] = dist[i][j];
				}
			}
		}
		
		return dist;
	}

	/**
	 * Output distance matrix
	 * 
	 * @param dist
	 */
	public void printDist(double[][] dist, List<Site> siteList) {
		for(int i = 0; i < siteList.size(); i++) {
			for(int j = 0; j < siteList.size(); j++) {
				System.out.print(dist[i][j] + "\t");
			}
			System.out.println();
		}
	}
}
